<?php

namespace Trawind\Extension\Models\Deploy;

use Illuminate\Database\Eloquent\Model;
use Trawind\Extension\Traits\CustomData;


class Language extends Model
{

    use CustomData;

    protected $table = 'deploy_languages';

    public $timestamps = false;

    const DEFAULT_LANGUAGE = 'zh_CN';

    protected $guarded = ['created_at', 'updated_at'];

    const LANGUAGE_TYPE_ENUM = [
        'zh_CN' => '简体中文(中国)',
        'en_US' => 'English(US)',
    ];

    public function business()
    {
        return $this->morphTo();
    }


    public static function generate($model, array $languages)
    {
        if (!empty($languages)) {
            $maxId = static::getMaxId();
            foreach ($languages as &$language) {
                $language['id'] = $maxId;
                $language['origin_type_id'] = static::$ORIGIN_CUSTOM;
            }
            unset($language);
            $model->languages()->createMany($languages);
        }
    }

}